<template>
  <div class="NoticeList">
    <!-- 顶部页面标题栏 -->
    <!-- <div class="header">
        <div class="backIcon" @click="back">
          <img slot="icon" src="../../assets/transfer/backIcon.png" class="iconImage" />
        </div>
        <div class="theme">通知公告</div>
      </div>-->
    <div style="display: flex;line-height: 30px;width: 250px;margin: 15px auto 0 auto;font-size: 14px;">
      <div @click="$router.replace('/activity')" style="flex: 1;text-align: center;background: #ececec;border-top-left-radius: 15px;border-bottom-left-radius: 15px;">街坊活动</div>
      <div style="flex: 1;text-align: center;background: #1699ee;color: #fff;border-top-right-radius: 15px;border-bottom-right-radius: 15px;">街坊议事</div>
    </div>
    <!-- 页面主体信息区域 -->
    <div class="outermostMargin">
      <!-- 懒加载 列表形式， item内复杂元素布局 -->
      <div class="listBox">
        <van-list v-model="loading" :finished="finished1" finished-text="没有了" @load="onLoad">
          <div v-for="(item, index) in list1" :key="index" style="min-height: 100px;padding: 30px">
            <div class="msgBox" @click="toDet(item)">
              <div class="textBox">
                <div class="titles">
                  <span class="mainTitle">{{ item.title }}</span>
                  <span class="time">{{ item.createTime }}</span>
                  <span class="nlfb">{{ item.regionName }}</span>
                </div>
                <!-- <div class="summary">
                        <span>{{ item.description }}</span>
                      </div>-->
              </div>
              <div class="imgBox">
                <img :src="item.url? picUrl(item.url): 'https://img.yzcdn.cn/vant/apple-1.jpg'" />
              </div>
            </div>
            <van-divider />
          </div>
        </van-list>
      </div>
    </div>
  </div>
</template>
<script>
  export default {
    name: "NoticeList",
    data() {
      return {
        activeTab: "街坊大喇叭",
        list1: [],
        list2: [],
        list3: [],
        finished1: false,
        finished2: false,
        finished3: false,
        loading: false,
        pageSize: 10,
        pageIndex1: 1,
        pageIndex2: 1,
        pageIndex3: 1,
        totalCount1: 0,
        totalCount2: 0,
        totalCount3: 0
      };
    },
    methods: {
      back() {
        this.$router.isBack = true; // 将返回状态置为触发态，以边路由监听触发返回动画
        this.$router.back(); // 路由向后退一步
      },
      toDet(item) {
        this.$router.push({
          path: "/noticeDet2",
          query: {
            detData: JSON.stringify(item)
          }
        });
      },
      tabchange() {
        this.pageIndex1 = 1;
        this.pageIndex2 = 1;
        this.pageIndex3 = 1;
        this.onLoad();
      },
      onLoad() {
        // 异步更新数据
        setTimeout(() => {
          // 向平安看点list push数据
          this.loading = true;
          switch (this.activeTab) {
            case "街坊大喇叭":
              this.requestPostNotice1();
              break;
            case "街坊小贴示":
              this.requestPostNotice2();
              break;
            case "街坊召集令":
              this.requestPostNotice3();
              break;
            default:
              break;
          }
          // 加载状态结束
          this.loading = false;
          // 数据全部加载完成
          if (this.list1.length >= this.totalCount1) {
            // 判断列表后台反馈数据总量=目前的数据量则结束
            this.finished1 = true;
          }
          // 数据全部加载完成
          if (this.list2.length >= this.totalCount2) {
            // 判断列表后台反馈数据总量=目前的数据量则结束
            this.finished2 = true;
          }
          // 数据全部加载完成
          if (this.list3.length >= this.totalCount3) {
            // 判断列表后台反馈数据总量=目前的数据量则结束
            this.finished3 = true;
          }
        }, 1000);
      },
      // 请求获取街坊议事
      requestPostNotice1() {
        let codes = ''
        if (this.slow.isAuth) {
        // if (this.slow.isAuth && this.slow.userInfo.subscribe != 0) {
          codes = ''
        } else {
          codes = '370503'
        }
        this.post("/procedure/get_activity", {
            pageSize: 10,
            pageIndex: this.pageIndex1,
            // dataAreaCode: localStorage.getItem("dataAreaCode")
            dataAreaCode: codes
          })
          .then(res => {
            console.log("反馈", res);
            if (res.list.length) {
              this.list1 = this.list1.concat(res.list);
              this.pageIndex1 += 1;
              this.totalCount1 = res.pageInfo.totalCount;
            }
          })
          .catch(err => {
            console.log("异常", err);
          });
      },
      requestPostNotice2() {
        this.post("Info_publish/loadInfo_public", {
            pageSize: 10,
            pageIndex: this.pageIndex2,
            // dataAreaCode: sessionStorage.getItem("dataAreaCode"),
            startTime: "2019-10-06 00:00:00",
            endTime: "2019-11-06 00:00:00",
            type: 2
          })
          .then(res => {
            console.log("反馈", res);
            if (res.array.length) {
              this.list2 = res.array;
              this.pageIndex2 += 1;
              this.totalCount2 = res.pageInfo.totalCount;
            }
          })
          .catch(err => {
            console.log("异常", err);
          });
      },
      requestPostNotice3() {
        this.post("Info_publish/loadInfo_public", {
            pageSize: 10,
            pageIndex: this.pageIndex3,
            // dataAreaCode: sessionStorage.getItem("dataAreaCode"),
            startTime: "2019-10-06 00:00:00",
            endTime: "2019-11-06 00:00:00",
            type: 3
          })
          .then(res => {
            console.log("反馈", res);
            if (res.array.length) {
              this.list3 = res.array;
              this.pageIndex3 += 1;
              this.totalCount3 = res.pageInfo.totalCount;
            }
          })
          .catch(err => {
            console.log("异常", err);
          });
      }
    }
  };
</script>
<style lang="scss" scoped>
  @import "~@/smobile.scss";
  .NoticeList {
    .header {
      padding: $sm-spaceing-block-sm 0 $sm-spaceing-block-sm 0;
      position: absolute;
      width: $sm-img-per-max;
      height: 21px;
      background: $sm-bg-color;
      z-index: 2;
      display: flex;
      flex-direction: row nowrap;
      justify-content: flex-start;
      .backIcon {
        position: absolute;
        white-space: nowrap;
        height: $sm-icon-px-md;
        z-index: 4;
        .iconImage {
          height: $sm-icon-px-md;
          width: $sm-icon-px-md;
          transform: rotateY(180deg);
        }
      }
      .theme {
        position: absolute;
        font-weight: bold;
        width: $sm-img-per-max;
        text-align: center;
        white-space: nowrap;
        z-index: 3;
      }
    }
    .outermostMargin {
      background: $sm-bg-color-grey;
      color: $sm-text-color;
      font-size: $sm-font-size-lg;
      overflow: auto;
      height: 100vh; // margin: 41px 0 0 0;
      .listBox {
        display: flex;
        flex-direction: column;
        background-color: $sm-bg-color;
        .msgBox {
          display: flex;
          flex-direction: row;
          flex-wrap: nowrap;
          justify-content: space-between;
          .textBox {
            .titles {
              display: flex;
              flex-direction: column;
              margin: $sm-spacing-col-xl 0 0 0;
              .mainTitle {
                font-size: $sm-font-size-title;
                font-weight: bold;
                color: $sm-color-title;
              }
              .nlfb{
                display: inline-block;
                text-align: center;
                font-size: 12px;
                background: #e5b03e;
                // padding: 1vw 2vw;
                border-radius:  4vw;
                color: #ffffff;
                width: 80%;
                height: 24px;
                line-height: 24px;
                padding-left: 2px;
                overflow: hidden;
                white-space: nowrap;
                text-overflow: ellipsis;
              }
              .time {
                margin: 2vw 0;
                color: $sm-text-color-grey;
                font-size: $sm-font-size-sm;
              }
            }
            .summary {
              margin: $sm-spacing-col-lg 0 $sm-spacing-col-lg 0;
              text-overflow: -o-ellipsis-lastline;
              overflow: hidden;
              text-overflow: ellipsis;
              display: -webkit-box;
              -webkit-line-clamp: 2;
              line-clamp: 2;
              -webkit-box-orient: vertical;
              color: $sm-color-title;
            }
          }
          .imgBox {
            // height: $sm-img-size-max;
            width: 40%;
            img {
              width: 100%;
            }
          }
        }
      }
    }
  }
</style>